package org.bulu.project.web.controller;

import lombok.RequiredArgsConstructor;
import org.bulu.project.common.result.Result;
import org.bulu.project.system.model.entity.UserVideo;
import org.bulu.project.system.service.UserVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/uservideo")
@RequiredArgsConstructor
public class UserVideoController {

    private final UserVideoService userVideoService;

    /**
     * 点赞或取消点赞
     * @param uid
     * @param vid
     * @param isLove
     * @param isSet
     * @return
     */
    @PostMapping("/love")
    public Result setLoveOrUnlove(
            @RequestParam Integer uid,
            @RequestParam Integer vid,
            @RequestParam boolean isLove,
            @RequestParam boolean isSet) {
        // 调用服务层方法并直接返回
        UserVideo userVideo=userVideoService.setLoveOrUnlove(uid, vid, isLove, isSet);
        return Result.success("操作成功");
    }
    @PostMapping("/collect")
    public Result collectOrCancel(
            @RequestParam Integer uid,
            @RequestParam Integer vid,
            @RequestParam boolean isCollect) {
        // 调用服务层方法
        userVideoService.collectOrCancel(uid, vid, isCollect);

        // 构建响应结果
        return Result.success("操作成功");
    }

    /**
     * 获取当前用户对指定视频的相关信息
     */
    @GetMapping("/userVideoInfo")
    public Result<UserVideo> getUserVideoInfo(
            @RequestParam Integer uid,
            @RequestParam Integer vid) {
        // 调用服务层方法获取信息
        UserVideo info = userVideoService.getUserVideoInfo(uid, vid);
        System.out.println("接收到的uid是：" + uid);
        System.out.println("接收到的vid是：" + vid);
        if (info == null){
            return Result.failed("该用户视频信息为空！！！");
        }else{
            return Result.success(info);
        }
        // 构建响应结果
    }

}


